#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
高德地图MCP服务 - 快速开始示例
最简单的使用方式演示
"""

import sys
import os

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from services.amap_mcp_service import create_amap_service
from cofig.amap_config import AmapConfig


def main():
    """快速开始示例"""
    
    print("=" * 60)
    print("  高德地图MCP服务 - 快速开始示例")
    print("=" * 60)
    
    # 检查配置
    if not AmapConfig.validate():
        print("\n⚠️  配置不完整，请先设置API Key：")
        print("   export AMAP_API_KEY='your_api_key'")
        print("   export AMAP_ENABLED='true'")
        print("\n或在 cofig/amap_config.py 中直接配置")
        return
    
    print("\n✅ 配置检查通过，开始初始化服务...")
    
    # 创建服务（会自动获取工具列表）
    service = create_amap_service(AmapConfig.AMAP_API_KEY)
    
    print("\n" + "-" * 60)
    print("  示例1: 查询天气")
    print("-" * 60)
    
    # 查询天气
    result = service.get_weather("北京")
    if result['success']:
        print(f"✅ 北京天气查询成功！")
        print(f"   结果: {result['data']}")
    else:
        print(f"❌ 查询失败: {result['error']}")
    
    print("\n" + "-" * 60)
    print("  示例2: 搜索地点")
    print("-" * 60)
    
    # 搜索地点
    result = service.search_poi("星巴克", "上海")
    if result['success']:
        print(f"✅ 搜索成功！")
        print(f"   结果: {result['data']}")
    else:
        print(f"❌ 搜索失败: {result['error']}")
    
    print("\n" + "-" * 60)
    print("  示例3: 规划路线")
    print("-" * 60)
    
    # 规划路线
    result = service.plan_route(
        origin="天安门",
        destination="鸟巢",
        mode="driving",
        city="北京"
    )
    if result['success']:
        print(f"✅ 路线规划成功！")
        print(f"   结果: {result['data']}")
    else:
        print(f"❌ 规划失败: {result['error']}")
    
    print("\n" + "=" * 60)
    print("  示例完成！")
    print("=" * 60)
    
    # 清理连接
    service.disconnect()
    
    print("\n💡 提示：")
    print("   1. 运行完整测试: python test/test_amap_mcp.py")
    print("   2. 交互模式: python test/test_amap_mcp.py --mode interactive")
    print("   3. 查看文档: doc/AMAP_MCP_README.md")
    print("   4. 启动服务: python app.py")


if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print("\n\n👋 程序被用户中断")
    except Exception as e:
        print(f"\n\n❌ 程序出错: {str(e)}")
        import traceback
        traceback.print_exc()

